package com.medicine.sys.controller;

import com.medicine.common.base.ResponseData;
import com.medicine.sys.bean.UserForm;
import com.medicine.sys.entity.User;
import com.medicine.sys.param.UserParam;
import com.medicine.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value="用户列表查询")
    @GetMapping("/list")
    public ResponseData list(UserParam userParam){
        return ResponseData.success("查询成功！",userService.selectList(userParam));
    }

    @ApiOperation(value="用户新增")
    @PostMapping
    public ResponseData install(@RequestBody UserForm userForm) throws Exception {
        userService.install(userForm);
        return ResponseData.success("新增成功！");
    }


    @ApiOperation(value="用户修改")
    @PutMapping
    public ResponseData update(@RequestBody UserForm userForm) throws Exception {
        userService.install(userForm);
        return ResponseData.success("修改成功！");
    }

    @ApiOperation(value="用户详情查询")
    @GetMapping("/{id}")
    public ResponseData list(@PathVariable String id) throws Exception {
        return ResponseData.success("查询成功！",userService.getId(id));
    }
}
